package view

import (
	"github.com/gogf/gf/v2/net/ghttp"
	"github.com/gogf/gf/v2/os/gview"
	"miaoyu/internal/library/resp"
	"miaoyu/internal/service"
)

/*
@Time : 2023/6/19 21:19
@Author : 56766
@File : tplView.logic.go
*/
func init() {
	tpl := &sTplResp{}
	service.RegisterTplResp(tpl)
}

// TplResp 通用tpl响应
type sTplResp struct {
}

// BuildSimpleTpl 返回一个tpl响应
func (s *sTplResp) BuildSimpleTpl(r *ghttp.Request) *resp.TplData {
	var t = resp.TplData{
		R:       r,
		Params:  gview.Params{},
		FuncMap: gview.FuncMap{},
	}

	return &t
}

// BuildTpl 返回一个tpl响应
func (s *sTplResp) BuildTpl(r *ghttp.Request) *resp.TplData {
	var t = resp.TplData{
		R:       r,
		Params:  gview.Params{},
		FuncMap: gview.FuncMap{},
	}
	t.Assign(gview.Params{
		"CommonIn": &commonBuildIn{
			httpRequest: t.R,
		},
	})
	return &t
}

// BuildCmsTpl 返回一个tpl响应
func (s *sTplResp) BuildCmsTpl(r *ghttp.Request) *resp.TplData {
	var t = resp.TplData{
		R:       r,
		Params:  gview.Params{},
		FuncMap: gview.FuncMap{},
	}
	//t.AssignCommonBuildIn()
	t.Assign(gview.Params{
		"CommonIn": &commonBuildIn{
			httpRequest: t.R,
		},
	})
	t.Assign(gview.Params{
		//"CmsIn": &cmsBuildIn{httpRequest: t.R},
	})
	return &t
}

// BuildTplWithLayout 返回一个tpl响应
func (s *sTplResp) BuildTplWithLayout(r *ghttp.Request, layout string) *resp.TplData {
	var t = resp.TplData{
		R:       r,
		Tpl:     layout,
		Params:  gview.Params{},
		FuncMap: gview.FuncMap{},
	}
	t.Assign(gview.Params{
		"CommonIn": &commonBuildIn{
			httpRequest: t.R,
		},
	})
	return &t
}
